import React, { PropTypes } from 'react'
import { Cascader,Form, Spin, Input,Select, InputNumber, Radio, Modal } from 'antd'

const FormItem = Form.Item

class TemplateModal extends React.Component {
  constructor (props) {
    super(props)
    this.state={
        cateList:[],
    }
  }
	
  handleChange1(value){
//		console.log(value)
  		const {onUsers} = this.props
  		onUsers(value)
  } 	
  
  onOk=()=>{
      const {validateFields,getFieldsValue,getFieldError}=this.props.form
      const {infoData} = this.props

      validateFields((errors) => {
        if (errors) {
          return
        }
        const params=getFieldsValue()
		
		params.documentId = infoData.document.id
		params.oldDepartmentId = infoData.document.departmentId
		params.oldUserId = infoData.document.createUserId
		delete params.documentType1
		delete params.documentType2
		delete params.documentType3
		delete params.documentType
//		console.log(params)
        this.props.onOk(params)
      })
  }  
    render(){
      	const { fileList,fetching, approvalUser,copyUser, value,cateList,assetsList } = this.state;
        const {department2,depUser,infoData} = this.props
//      console.log(infoData)
//      console.log(localStorage.getItem("user"))
//      console.log(department2)
//      console.log(depUser)
        const depChild = [];
	    for (let i = 0; i < department2.length; i++) {
		  depChild.push(<Option key={department2[i].id}>{department2[i].name}</Option>);
		}
	    const userChild = [];
	    for (let i = 0; i < depUser.length; i++) {
		  userChild.push(<Option key={depUser[i].userId}>{depUser[i].username}</Option>);
		}
        const formItemLayout = {
          labelCol: {
            span: 6
          },
          wrapperCol: {
            span: 14
          }
        }
        const {getFieldDecorator}=this.props.form
        const {
          visible,
          type,
          item = {},
          onOk,
          onCancels,
        }=this.props

        const modalOpts = {
          title:'档案移交',
          visible:visible,
          onOk: this.onOk,
          onCancel:onCancels,
          wrapClassName: 'vertical-center-modal'
        }
       
        return (
          <Modal {...modalOpts}>
            <Form>

              <FormItem label='移交部门：' hasFeedback {...formItemLayout}>
                {getFieldDecorator('documentType1', {
  			      initialValue:infoData?infoData.document.departmentName:"",
                  rules: [
                    {
                      required: false,
                      message: '未填写'
                    }
                  ]
                })(
                  <Input disabled={true} />
                )}
              </FormItem>
          
              <FormItem label='管理人员：' hasFeedback {...formItemLayout}>
                {getFieldDecorator('documentType2', {
  			      initialValue:infoData?infoData.document.createUserName:"",
                  rules: [
                    {
                      required: false,
                      message: '未填写'
                    }
                  ]
                })(
                  <Input disabled={true} />
                )}
              </FormItem>
              
              <FormItem label='文档范围：' hasFeedback {...formItemLayout}>
                {getFieldDecorator('type', {
  			      initialValue:"单个文档",
                  rules: [
                    {
                      required: false,
                      message: '未填写'
                    }
                  ]
                })(
                  <Input disabled={true} />
                )}
              </FormItem>
              
              <FormItem label='文档标题：' hasFeedback {...formItemLayout}>
                {getFieldDecorator('documentType3', {
  			      initialValue:infoData?infoData.document.type:"",
                  rules: [
                    {
                      required: false,
                      message: '未填写'
                    }
                  ]
                })(
                  <Input disabled={true} />
                )}
              </FormItem>              

              <FormItem label='接收部门：' hasFeedback {...formItemLayout}>
                {getFieldDecorator('departmentId', {
  
                  rules: [
                    {
                      required: true,
                      message: '未填写'
                    }
                  ]
                })(
                  <Select onChange={this.handleChange1.bind(this)}>
                        {depChild}
                    </Select>
                )}
              </FormItem>
        
              <FormItem label='接收人：' hasFeedback {...formItemLayout}>
                {getFieldDecorator('userId', {
  
                  rules: [
                    {
                      required: true,
                      message: '未填写'
                    }
                  ]
                })(
                  <Select>
                        {userChild}
                    </Select>
                )}
              </FormItem>
              
              <FormItem label='移交备注：' hasFeedback {...formItemLayout}>
                {getFieldDecorator('remark', {
  			      initialValue:"",
                  rules: [
                    {
                      required: false,
                      message: '未填写'
                    }
                  ]
                })(
                  <Input placeholder="请输入" type="textarea" rows={4}/>
                )}
              </FormItem>              
              
              <FormItem label='处理人：' hasFeedback {...formItemLayout}>
                {getFieldDecorator('documentType', {
  			      initialValue:sessionStorage.getItem("user"),
                  rules: [
                    {
                      required: false,
                      message: '未填写'
                    }
                  ]
                })(
                  <Input disabled={true} />
                )}
              </FormItem>
              
            </Form>
          </Modal>
        )
    }
}

export default Form.create()(TemplateModal)
